use SilenthinkLog
go

if OBJECT_ID('[App.Exception]') is not null
drop table [App.Exception]
go

create table [App.Exception](
[Id] int identity(1,1) not null,
[Machine] varchar(80) not null,
[Server] varchar(80) not null,
[ServerIp] varchar(20) not null,
[Level] tinyint not null,
[ExType] varchar(150) not null,
[ExSource] varchar(150) not null,
[ExMessage] varchar(400) not null,
[ExStackTrace] varchar(4000) not null,
[Variables] nvarchar(4000),
[StatusCode] int not null,
[Url] varchar(200) not null,
[Referer] varchar(200),
[UserAgent] varchar(200) not null,
[ClientIp] varchar(20) not null,
[CreatedBy] varchar(50),
[CreatedOn] datetime not null
)
go

ALTER TABLE [App.Exception] ADD CONSTRAINT [Pk.App.Exception] PRIMARY KEY(Id)
go
ALTER TABLE [App.Exception] ADD CONSTRAINT [Df.App.Exception.CreatedOn] DEFAULT (getdate()) FOR CreatedOn
go

if OBJECT_ID('[Proc.App.Exception.Add]') is not null
drop proc [Proc.App.Exception.Add]
go

CREATE PROCEDURE [Proc.App.Exception.Add](
@Machine varchar(80) = null, 
@Server varchar(80) = null, 
@ServerIp varchar(20) = null, 
@Level tinyint = null, 
@ExType varchar(150) = null, 
@ExSource varchar(150) = null, 
@ExMessage varchar(400) = null, 
@ExStackTrace varchar(4000) = null, 
@Variables nvarchar(4000) = null, 
@StatusCode int = 0, 
@Url varchar(200) = null, 
@Referer varchar(200) = null, 
@UserAgent varchar(200) = null, 
@ClientIp varchar(20) = null,
@CreatedBy varchar(50) = null, 
@CreatedOn datetime
)
AS
BEGIN
    SET NOCOUNT ON;
	INSERT INTO [App.Exception]([Machine],[Server],[ServerIp],[Level],[ExType],[ExSource],[ExMessage],[ExStackTrace],[Variables],[StatusCode],[Url],[Referer],[UserAgent],[ClientIp],[CreatedBy],[CreatedOn]) 
	VALUES(@Machine,@Server,@ServerIp,@Level,@ExType,@ExSource,@ExMessage,@ExStackTrace,@Variables,@StatusCode,@Url,@Referer,@UserAgent,@ClientIp,@CreatedBy,@CreatedOn) 
END
GO